package action;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import po.User;
import po.UserDAO;



public class CQM_LoginAction {
private String name;
private String password;
public String getName() {
	return name;
}
public void setName(String name) {
	this.name = name;
}
public String getPassword() {
	return password;
}
public void setPassword(String password) {
	this.password = password;
}
public String execute(){
	


	User user=new User(name+"@126.com",password);
	List list=new UserDAO().findByExample(user);

   
	if(list.size()>0){
		
	     Iterator it=list.iterator();
	     while(it.hasNext()){
	    	 
	    	 User use=(User)it.next();

	    	 ServletActionContext.getRequest().getSession().setAttribute("id", use.getId());
	    	 ServletActionContext.getRequest().getSession().setAttribute("name", use.getEmail());
	    	 
	     }
		return "mainpage";
		
	}else{
		
		 ServletActionContext.getRequest().setAttribute("cuowu","请检查用户名和密码"); 
		return "input";
	}
	
	
	
}





}
